package com.rayo.accesscontrollercopy.model.db.dao;

import com.rayo.accesscontrollercopy.model.db.DbHelp;
import com.rayo.accesscontrollercopy.model.db.bean.LockData;

import java.util.List;

/**
 * Created by lyc-pc on 17/5/17.
 */

public class LockImp implements LockDao {
    @Override
    public LockData findBylockId(String lockId) {
        List<LockData> list = DbHelp.getQueryByWhere(LockData.class, "lockid", new String[]{lockId});
        if (list.size() > 0)
            return list.get(0);
        return null;
    }

    @Override
    public void addLock(LockData lockData) {
        DbHelp.insert(lockData);
    }

    @Override
    public void deleteAll() {
        DbHelp.deleteAll(LockData.class);
    }

    @Override
    public void updateLock(LockData lockData) {
        DbHelp.deleteWhere(LockData.class, "lockid",
                new String[]{String.valueOf(lockData.getLockid())});
        addLock(lockData);
    }
}
